//
//  PersonalViewController.m
//  Toyohu
//
//  Created by celia on 16/3/30.
//  Copyright (c) 2016年 celia. All rights reserved.
//

#import "PersonalViewController.h"

#import "MyPersonalInfoViewController.h"
#import "PersonViewCell.h"
#import "ItemTableViewCell.h"

#import "IssueViewController.h"
#import "AnswerViewController.h"
#import "myCollectViewController.h"

static NSString *PersonReuseId = @"PersonViewCell";
static NSString *ItemReuseId = @"ItemTableViewCell";
#define WIDTH self.view.bounds.size.width
#define HEIGHT self.view.bounds.size.height
@interface PersonalViewController ()<UITableViewDelegate,UITableViewDataSource>{
    UITableView *myTableView;
    
}

@end

@implementation PersonalViewController

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:NO];
    self.navigationController.navigationBar.hidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.hidden = NO;
    [self CreateNavBar];
    myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, WIDTH, HEIGHT-64-44) style:UITableViewStylePlain];
    myTableView.delegate = self;
    myTableView.dataSource = self;
    [myTableView registerNib:[UINib nibWithNibName:@"PersonViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:PersonReuseId];
    [myTableView registerNib:[UINib nibWithNibName:@"ItemTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:ItemReuseId];
    [self.view addSubview:myTableView];
    self.automaticallyAdjustsScrollViewInsets=NO;
    
    UIView *View = [[UIView alloc]initWithFrame:CGRectZero];
    myTableView.tableFooterView= View;
    
    
    
}

-(void)CreateNavBar{
    //导航栏右边项
    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeSystem];
    rightButton.frame = CGRectMake(0, 0, 20, 20);
    [rightButton setBackgroundImage:[UIImage imageNamed:@"素彩网www.sc115.com-056@2x"] forState:UIControlStateNormal];
    [rightButton addTarget:self action:@selector(goIntoSettingPage) forControlEvents:UIControlEventTouchDown];
    
    UIBarButtonItem *rightButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
    self.navigationItem.rightBarButtonItem = rightButtonItem;
    
    
    //导航栏左边项
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeSystem];
    leftButton.frame = CGRectMake(0, 0, 10, 15);
    [leftButton setBackgroundImage:[UIImage imageNamed:@"ARROW---LEFT@2x"] forState:UIControlStateNormal];
    [leftButton addTarget:self action:@selector(goBackPreviousPage) forControlEvents:UIControlEventTouchDown];
    
    UIBarButtonItem *leftButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem = leftButtonItem;
}
//进入设置页面
-(void)goIntoSettingPage{
    MyPersonalInfoViewController *settingVC = [[MyPersonalInfoViewController alloc]init];
//    settingVC.hidesBottomBarWhenPushed = YES;
//    settingVC.tabBarController.tabBar.hidden = YES;
    [self.navigationController pushViewController:settingVC animated:YES];
}
//返回到上一个页面
-(void)goBackPreviousPage{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

#pragma mark -----UITableViewDelegate DataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row==0) {
        PersonViewCell*cell = [myTableView dequeueReusableCellWithIdentifier:PersonReuseId];
        myTableView.rowHeight = 253;
        if (!cell) {
            cell = (PersonViewCell *)[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier: PersonReuseId];
        }
        cell.babyImg.image = [UIImage imageNamed:@"图层-2@2x"];
        cell.babyImg.layer.cornerRadius = 52.5;
        cell.babyImg.clipsToBounds = YES;
        cell.name.text = @"希宝贝的妈咪";
        cell.content.text = @"通过关系，我们成长自己，成长自己，我们改善了与他人的关系，你的幸福，如果你不负责，还能是谁？";
        cell.baby.text = @"女宝宝 3岁";
        return cell;
    }
    
    else if(indexPath.row==1){
        ItemTableViewCell*cell = [myTableView dequeueReusableCellWithIdentifier:ItemReuseId];
        myTableView.rowHeight = 45;
        if (!cell) {
            cell = (ItemTableViewCell *)[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier: ItemReuseId];
        }
        cell.name.text = @"我发布的";
        cell.count.text = @"3";
        cell.img.image = [UIImage imageNamed:@"ARROW---LEFT-拷贝@2x"];
        return cell;
    }
    else if(indexPath.row==2){
        ItemTableViewCell*cell = [myTableView dequeueReusableCellWithIdentifier:ItemReuseId];
        myTableView.rowHeight = 45;
        if (!cell) {
            cell = (ItemTableViewCell *)[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier: ItemReuseId];
        }
        cell.name.text = @"我回复的";
        cell.count.text = @"2";
        cell.img.image = [UIImage imageNamed:@"ARROW---LEFT-拷贝@2x"];
        return cell;
    }
    else {
        ItemTableViewCell*cell = [myTableView dequeueReusableCellWithIdentifier:ItemReuseId];
        myTableView.rowHeight = 45;
        if (!cell) {
            cell = (ItemTableViewCell *)[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier: ItemReuseId];
        }
        cell.name.text = @"我收藏的";
        cell.count.text = @"2";
        cell.img.image = [UIImage imageNamed:@"ARROW---LEFT-拷贝@2x"];
        return cell;
    }
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row==1) {
        IssueViewController *issueVC = [[IssueViewController alloc]init];
        [self.navigationController pushViewController:issueVC animated:YES];
    }
    else if (indexPath.row==2){
        AnswerViewController *ansVC= [[AnswerViewController alloc]init];
        [self.navigationController pushViewController:ansVC animated:YES];
    }
    else if (indexPath.row==3){
        myCollectViewController *collectVC= [[myCollectViewController alloc]init];
        [self.navigationController pushViewController:collectVC animated:YES];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
